package com.tfjybj.itoo.exam.provider.controller;

import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.SignInEntity;
import com.tfjybj.itoo.exam.model.SignInModel;
import com.tfjybj.itoo.exam.provider.service.SignInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * SignInController
 * signIn表
 *
 * @author 郭满亮
 * @version 2.0.0
 * @since 2.0.0 2019-03-19 09:21:41
 */
@Api(tags = {"signIn签到表接口"})
@RequestMapping(value = "/signIn")
@RestController
public class SignInController {

    @Resource
    private SignInService signInService;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model SignInModel
     * @return 添加的结果
     * @author 郭满亮
     * @since 2.0.0 2019-03-19 09:21:41
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody SignInModel model) {
        SignInEntity signInEntity = new SignInEntity();
        BeanUtils.copyProperties(model, signInEntity);
        signInService.save(signInEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功          
     * @author 郭满亮
     * @since 2.0.0 2019-03-19 09:21:41
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        signInService.removeById(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 郭满亮
     * @since 2.0.0 2019-03-19 09:21:41
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiImplicitParam(name = "ids", value = "ids", dataType = "List<String>", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        signInService.removeByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model SignInModel
     * @return 修改后的结果
     * @author 郭满亮
     * @since 2.0.0 2019-03-19 09:21:41
     */
    @ApiOperation(value = "根据id修改signIn")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody SignInModel model) {
        SignInEntity signInEntity = new SignInEntity();
        BeanUtils.copyProperties(model, signInEntity);
        signInService.updateById(signInEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找SignIn
     *
     * @param id 主键id
     * @return 根据id查找的结果
     * @author 郭满亮
     * @since 2.0.0 2019-03-19 09:21:41
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        SignInEntity signInEntity = signInService.getById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", signInEntity);
    }

    /**
     * 分页查询所有SignIn
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @return 分页查询的结果
     * @author 郭满亮
     * @since 2.0.0 2019-03-19 09:21:41
     */
    @ApiOperation(value = "分页查询所有SignIn")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo",value = "页码",required = true,example = "1")@PathVariable Integer pageNo,
								   @ApiParam(name = "pageSize",value = "页数",required = true,example = "10")@PathVariable Integer pageSize) {
        PageInfo<SignInEntity> signIns = signInService.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", signIns);
    }
	
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     * 查询历史签到记录
     * @param teacherId 教师id
     * @param teachClassId 上课班id
     * @return 签到记录
     * @author 郭满亮
     * @since 2019年3月20日09:15:45
     */
    @ApiOperation(value = "查询历史签到记录")
    @PostMapping(value = {"/queryHistorySingin/{teacherId}/{teachClassId}"})
    public ItooResult queryHistorySingin(@ApiParam(value = "教师id",required = true) @PathVariable String teacherId,
                                         @ApiParam(value = "上课班id",required = true) @PathVariable String teachClassId){
        return signInService.queryHistorySingin(teacherId,teachClassId);
    }
    /**
     * 查询是否存在未结束签到
     * @param teacherId 教师id
     * @param teachClassId 上课班id
     * @return 查询结果
     * @author 郭满亮
     * @since 2019年3月24日17:57:31
     */
    @ApiOperation(value = "查询是否存在未结束签到")
    @PostMapping(value = {"/queryIsOffSingin/{teacherId}/{teachClassId}"})
    public ItooResult queryIsOffSingin(@ApiParam(value = "教师id",required = true) @PathVariable String teacherId,
                                         @ApiParam(value = "上课班id",required = true) @PathVariable String teachClassId){
        return signInService.queryIsOffSingin(teacherId,teachClassId);
    }

    /**
     * 添加签到记录
     * @param signInEntity  model
     * @return 添加结果
     * @author 郭满亮
     * @since   2019年3月20日11:50:47
     */
    @ApiOperation(value = "添加签到记录")
    @PostMapping(value = {"/createSignin"})
    public ItooResult createSignin(@RequestBody SignInEntity signInEntity){
        return signInService.createSignin(signInEntity);
    }

    /**
     * 签到结束,修改状态
     * @param teachClassId 上课班id
     * @return 结果
     * @author 郭满亮
     * @since 2019年3月20日14:39:22
     */
    @ApiOperation(value = "签到结束,修改状态")
    @PostMapping(value = {"/modifySigninState/{teachClassId}"})
    public ItooResult modifySigninState(@ApiParam(value = "teachClassId",required = true) @PathVariable String teachClassId) {
       return signInService.modifySigninState(teachClassId);
    }
}    
